<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.solead.utils.SoleadUtil" %>
<%@ page import="weaver.interfaces.solead.wcf.WcfUtil" %>
<%@ page import="java.util.Map" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    String requestid = "126209";
    String tablename = "formtable_main_155";
    out.print( ">>>>WeaKhywywhspAction=" + requestid + "<br/>" );
    String message = "";
    String sql = "select id,ywhbdm,ywhbmcwb,zdmwb,gsbh,jskhxjzh,jskpdzjdh,xy,ysyld,sfxzkh " +
            "from " + tablename + " where requestid=?";
    rs.executeQuery( sql, requestid );
    rs.next();
    String mainid = Util.null2String( rs.getString( "id" ) );
    //是否新增业务伙伴
    String sfxzkh = Util.null2String( rs.getString( "sfxzkh" ) );
    //业务伙伴代码
    String ywhbdm = Util.null2String( rs.getString( "ywhbdm" ) );
    String key = "0".equals(sfxzkh)?"":ywhbdm;
    //业务伙伴名称文本
    String ywhbmcwb = Util.null2String( rs.getString( "ywhbmcwb" ) );
    //业务伙伴类型
    String ywhblxwb = "C";
    //组代码文本
    String zdmwb = Util.null2String( rs.getString( "zdmwb" ) );
    //国税编号
    String gsbh = Util.null2String( rs.getString( "gsbh" ) );
    //金税开户行及账号
    String jskhxjzh = Util.null2String( rs.getString( "jskhxjzh" ) );
    //金税开票地址及电话
    String jskpdzjdh = Util.null2String( rs.getString( "jskpdzjdh" ) );
    //行业
    String xy = Util.null2String( rs.getString( "xy" ) );
    //月使用量(吨)
    String ysyld = Util.null2String( rs.getString( "ysyld" ) );
    JSONObject header = new JSONObject();
    if("0".equals(sfxzkh)){
        header.put( "CardCode", ywhbdm );
    }
    header.put( "CardName", ywhbmcwb );
    header.put( "CardType", ywhblxwb );
    header.put( "GroupCode", zdmwb );
    header.put( "FederalTaxID", gsbh );
    header.put( "GTSBankAccountNo", jskhxjzh );
    header.put( "GTSBillingAddrTel", jskpdzjdh );
    header.put( "U_Trade", xy );
    header.put( "U_MQty", ysyld );
    out.print( ">>>>>header=" + header.toJSONString() + "<br/>" );
    JSONArray bodyList1 = new JSONArray();
    String sql1 = "select lxr,dh from " + tablename + "_dt1  where  mainid=?";
    rs.executeQuery( sql1, mainid );
    while (rs.next()) {
        //联系人
        String lxr = Util.null2String( rs.getString( "lxr" ) );
        //电话
        String dh = Util.null2String( rs.getString( "dh" ) );
        JSONObject body = new JSONObject();
        body.put( "Name", lxr );
        body.put( "Phone1", dh );
        out.print( ">>>>>body=" + body.toJSONString() + "<br/>" );
        bodyList1.add( body );
    }
    out.print( ">>>>>bodyList1=" + bodyList1.size() + "<br/>" );
    JSONArray bodyList2 = new JSONArray();
    String sql2 = "select dzbs,xxdz from " + tablename + "_dt2  where  mainid=?";
    rs.executeQuery( sql2, mainid );
    while (rs.next()) {
        //地址标识
        String dzbs = Util.null2String( rs.getString( "dzbs" ) );
        //详细地址
        String xxdz = Util.null2String( rs.getString( "xxdz" ) );
        JSONObject body = new JSONObject();
        body.put( "AddressName", dzbs );
        body.put( "BuildingFloorRoom", xxdz );
        out.print( ">>>>>body=" + body.toJSONString() + "<br/>" );
        bodyList2.add( body );
    }
    out.print( ">>>>>bodyList2=" + bodyList2.size() );
    String param = SoleadUtil.ywhb_XMLContent( header, bodyList1, bodyList2 );
    out.print( ">>>>>param=" + param + "<br/>" );
    Map<String, String> resultMap = WcfUtil.send( param, "test", "2",key);
    out.print( ">>>>>resultMap=" + resultMap.toString() + "<br/>" );
    String code = Util.null2String( resultMap.get( "code" ) );
    String msg = Util.null2String( resultMap.get( "msg" ) );
    out.print( ">>>>>code=" + code + ",msg=" + msg + "<br/>" );
%>
